// #import "mscorlib.dll"

#using <mscorlib.dll>
#using <System.DLL>
#include <string>
#include <iostream>
#include <msclr\marshal_cppstd.h>

#include <Windows.h>
#include "Shlwapi.h"
#include <tchar.h>

using namespace System;
using namespace Microsoft::Win32;

using namespace std;


void getAllRegistry(RegistryKey^);
void test(char* cptr)
{
	while(*cptr != '.')
		std::cout << *cptr++<<std::endl;
}

int main()
{
	/*wchar_t buf[] = _T("c:\\a\\b\\c\\d.txt");
	wchar_t *cptr = buf;

	std::cout << cptr << std::endl;

	PathRemoveFileSpec(cptr);

	std::cout << cptr << std::endl;*/
	char *cptr = "Long long times ago, there is a tiger in the forest.";
	test(cptr);



	/*
	// wchar_t* TENCENT_REG_PATH = L"Software\\Tencent\\PlatForm_Type_List";
	RegistryKey ^pRegKey = Registry::CurrentUser;
	pRegKey = pRegKey->OpenSubKey(L"Software\\Tencent\\PlatForm_Type_List");
	Object ^pValue = pRegKey->GetValue("LastLoginType");
	Console::WriteLine("LastLoginType: {0}, name: {1}", pValue, pRegKey->Name);

	pRegKey = pRegKey->OpenSubKey(L"1");
	pValue = pRegKey->GetValue("TypePath");
	Console::WriteLine("TypePath: {0}, name: {1}", pValue, pRegKey->Name);
	// string value = msclr::interop::marshal_as<std::string>(pValue);
	// std::cout << value << std::endl;
	*/

	RegistryKey ^pRegKey = Registry::CurrentUser;
	pRegKey = pRegKey->OpenSubKey(L"Software\\Tencent");
	getAllRegistry(pRegKey);
	return 0;
}

// void getAllRegistry(RegistryKey^ pRegKey = Registry::CurrentUser, System::String^ subRegKey)
void getAllRegistry(RegistryKey^ pRegKey = Registry::CurrentUser)
{
	// if(pRegKey == NULL) // Error C2446: '==' : no conversion from 'int' to 'Microsoft::Win32::RegistryKey ^'
		// return;

	Console::WriteLine("{0}\n", pRegKey->Name);
	int valueCount = pRegKey->ValueCount;
	int subKeyCount = pRegKey->SubKeyCount;

	// array<System::String^> valueNames = pRegKey->GetValueNames();
	// Error C3149: 'cli::array<Type>' : cannot use this type here without a top-level '^'	
	array<System::String^> ^valueNames = pRegKey->GetValueNames();
	array<System::String^> ^subKeyNames = pRegKey->GetSubKeyNames();

	int i = 0;
	Object ^pValue = NULL;
	valueCount == 0 ? Console::WriteLine("    Empty") : Console::WriteLine("    Values: \n");
	for(i = 0; i < valueCount; ++i)
	{
		Console::WriteLine("    {0}: {1}\n", valueNames[i], pRegKey->GetValue(valueNames[i]));
	}

	Console::WriteLine();
	for(i = 0; i < subKeyCount; ++i)
	{
		getAllRegistry(pRegKey->OpenSubKey(subKeyNames[i]));
	}
}